<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
	xmlns:h="http://java.sun.com/jsf/html"
	xmlns:f="http://java.sun.com/jsf/core"
	xmlns:ui="http://java.sun.com/jsf/facelets"
	xmlns:p="http://primefaces.org/ui">

<h:head>
	<style>
.ui-widget,.ui-widget .ui-widget {
	font-size: 11px !important;
}
</style>
	<title>Cadastro de Condicoes de Pagamento</title>
	<link rel="stylesheet" type="text/css" href="css/estilos.css" />
</h:head>
<body>
	<h:form id="mCondicaoForm">
		<p:messages id="messages" showDetail="false" autoUpdate="true"
			closable="true" />
		<p:panel id="mCondicaoPanel" style="border: none;">

			<h3>Cadastro de Condicoes de Pagamento</h3>

			<h:panelGrid columns="1" cellpadding="2">
				<h:outputText value="Codigo: " />
				<p:inputText id="mCondicaoIdCondicao"
					value="#{beanCondicao.condicao.id}" maxlength="40" size="5"
					disabled="true" />
			</h:panelGrid>


			<h:panelGrid columns="5" cellpadding="2">

				<h:outputText value="Condicao *" />
				<h:outputText value="Codigo" />
				<h:outputText value="Forma de Pagamento *" />
				<h:outputText value="" />
				<h:outputText value="Tx. Juros (%)" />

				<p:inputText id="mCondicaoCondicao"
					value="#{beanCondicao.condicao.descricao}" size="65" />
				<p:inputText id="mCondicaoIdForma"
					value="#{beanCondicao.condicao.formaPagamento.id}" maxlength="40"
					size="5">
					<p:ajax event="change" process="@this"
						listener="#{beanCondicao.hotFindForma}"
						update=":mCondicaoForm:mCondicaoFormaP" />
				</p:inputText>
				<p:inputText id="mCondicaoFormaP"
					value="#{beanCondicao.condicao.formaPagamento.descricao}" size="20"
					disabled="true" binding="#{beanCondicao.formaPagamento}" />
				<p:commandButton icon="ui-icon-search" id="mCondicaoSelectForma"
					title="Selecionar Forma de Pagamento"
					onclick="dConsultaForma.show()" />
				<p:inputText value="#{beanCondicao.condicao.taxaJuros}" size="9" />

			</h:panelGrid>

			<br></br>
			<p:separator />

			<h:panelGrid columns="4" id="mCondicaoCamposParcela">
				<h:outputText value="Numero" />
				<h:outputText value="Dias" />
				<h:outputText value="Percentual (%)" />
				<h:outputText value="" />

				<p:inputText id="mCondicaoNumero"
					value="#{beanCondicao.numeroParcelas}" disabled="true" />

				<p:inputText id="mCondicaoDias" value="#{beanCondicao.parcela.dias}">
					<p:ajax event="change" />
				</p:inputText>

				<p:inputText id="mCondicaoPercentual"
					value="#{beanCondicao.parcela.perc}">
					<p:ajax event="change" />
				</p:inputText>

				<p:commandButton icon="ui-icon-plus" id="mCondicaoAddParcela"
					action="#{beanCondicao.addParcela}"
					update="mCondicaoPanelParcelas, :mCondicaoForm:mCondicaoCamposParcela"
					process="@this" />
			</h:panelGrid>

			<p:outputPanel id="mCondicaoPanelParcelas">
				<br></br>
				<p:separator />

				<p:dataTable value="#{beanCondicao.parcelas}" var="parcela"
					emptyMessage="Não Há Parcelas">
					<p:column headerText="Parcela">
						<h:outputText value="#{parcela.numero}" />
					</p:column>
					<p:column headerText="Dias">
						<h:outputText value="#{parcela.dias}" />
					</p:column>
					<p:column headerText="Percentual">
						<h:outputText value="#{parcela.perc}" />
					</p:column>
					<p:column width="10">
						<p:commandButton icon="ui-icon-trash" title="Remover"
							action="#{beanCondicao.removeParcela}"
							id="mCondicaoRemoveParcela"
							update=":mCondicaoForm:mCondicaoPanelParcelas, :mCondicaoForm:mCondicaoCamposParcela">
							<f:setPropertyActionListener target="#{beanCondicao.parcela}"
								value="#{parcela}"></f:setPropertyActionListener>
						</p:commandButton>
					</p:column>
				</p:dataTable>
			</p:outputPanel>
			<br></br>
			<p:separator />

			<h:panelGrid columns="3" style="float: right;">
				<p:commandButton id="mCondicaoSalvar" value="Salvar"
					action="#{beanCondicao.save}" update="mCondicaoForm" />
				<p:commandButton id="mCondicaoLimpar" value="Limpar"
					action="#{beanCondicao.reinit}" update="mCondicaoForm" />
				<p:commandButton id="mCondicaoVoltar" value="Voltar"
					onclick="history.back()" />
			</h:panelGrid>


			<h:panelGrid columns="4" cellpadding="2" style="float: left;">
				<h:outputText value="Cadastro" /> 
				<p:inputText id="mCondicaoDataCad" value="#{beanCondicao.condicao.criacao}" size="7"
					disabled="true" />

				<h:outputText value="Ultima Alter. " />

				<p:inputText id="mCondicaoDataAlteracao" value="#{beanCondicao.condicao.alteracao}" size="7"
					disabled="true" />
			</h:panelGrid>
		</p:panel>

		<p:dialog header="Consultar Forma de Pagamento"
			widgetVar="dConsultaForma" id="mCondicaoConsultaForma"
			resizable="false">
			<ui:include src="/formaPagamento/pConsultaFormaPagamento.xhtml"></ui:include>
		</p:dialog>
	</h:form>
</body>
</html>